package com.linghang.wusthelpercompetition.mapper;

import com.github.pagehelper.Page;
import com.linghang.wusthelpercompetition.dto.CompetitionPostPageDTO;
import com.linghang.wusthelpercompetition.dto.CompetitionPostUpdateDTO;
import com.linghang.wusthelpercompetition.entity.CompetitionPost;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CompetitionPostMapper {


    /**
     * 插入一条新帖子
     * @param competitionPost
     */
    @Insert("insert into competition_post(student_id,competition_name,competition_introduction,requirement,contact_information,status,end_update_time) " +
            "values(#{studentId},#{competitionName},#{competitionIntroduction},#{requirement},#{contactInformation},#{status},#{endUpdateTime})")
    void insert(CompetitionPost competitionPost);


    /**
     * 修改帖子
     * @param competitionPost
     */
    void update(CompetitionPost competitionPost);

    /**
     * 删除帖子
     * @param cid
     */
    @Delete("delete from competition_post where cid=#{cid}")
    void deleteByCid(long cid);

    /**
     * 分页查询
     * @param competitionPostPageDTO
     * @return
     */
    Page<CompetitionPost> pageQuery(CompetitionPostPageDTO competitionPostPageDTO);

    /**
     * 根据cid查询帖子信息
     * @param cid
     * @return
     */
    @Select("select * from competition_post where cid=#{cid}")
    CompetitionPost getByCid(Long cid);

    /**
     * 查询所有帖子
     */
    @Select("select * from competition_post")
    List<CompetitionPost> getAllPost();


    /**
     * 根据学号查询帖子总数
     * @param studentId
     * @return
     */
    @Select("select count(*) from competition_post where student_id=#{studentId}")
    Long getTotalByStudentId(String studentId);
}
